<?php

class WebsiteController extends MyController
{
	function init()
	{
		parent::init();
		$controller_id = str_replace('controller','',strtolower(__CLASS__));
		$this->data['controller_id'] = $controller_id;
	}
	
	function actionIndex()
	{
		$this->redirect(array($this->data['controller_id'].'/edit_thongtinchung'));
	}
	
	function actionEdit_thongtinchung($message = "")
	{
		$form = array();
		$form["company_name"] 		= $this->data["website"]["company_name"];
		$form["company_address"] 	= $this->data["website"]["company_address"];
		$form["company_office"] 	= $this->data["website"]["company_office"];
		$form["phone"] 				= $this->data["website"]["phone"];
		$form["tax_code"] 			= $this->data["website"]["tax_code"];
		
		$form["director_name"] 		= $this->data["website"]["director_name"];
		$form["chief_accountant"] 	= $this->data["website"]["chief_accountant"];
		$form["cashier_name"] 		= $this->data["website"]["cashier_name"];
		
		$this->data["form"] = $form;
		
		$this->data["message"] = $message;
		
		$this->render("form_edit_thongtinchung", $this->data);
	}
	
	function actionSave_thongtinchung()
	{
		$website = website::model()->findByPk(1);
		
		$website->company_name 			= Yii::app()->getRequest()->getPost("company_name");
		$website->company_address		= Yii::app()->getRequest()->getPost("company_address");
		$website->company_office		= Yii::app()->getRequest()->getPost("company_office");
		$website->phone					= Yii::app()->getRequest()->getPost("phone");
		$website->tax_code 				= Yii::app()->getRequest()->getPost("tax_code");
		
		$website->director_name 		= Yii::app()->getRequest()->getPost("director_name");
		$website->chief_accountant 		= Yii::app()->getRequest()->getPost("chief_accountant");
		$website->cashier_name 			= Yii::app()->getRequest()->getPost("cashier_name");
		
		$website->save();
		$this->redirect(array($this->data['controller_id'].'/edit_thongtinchung',
			"message"=>"Đã lưu thông tin."));
	}
	
	function actionEdit_media($message = "")
	{
		$form = array();
		
		$form["image_folder"] 	= $this->data["website"]["image_folder"];
		$form["image_type"] 	= $this->data["website"]["image_type"];
		$form["image_maxsize"] 	= $this->data["website"]["image_maxsize"];
		
		$form["video_folder"] 	= $this->data["website"]["video_folder"];
		$form["video_type"] 	= $this->data["website"]["video_type"];
		$form["video_maxsize"] 	= $this->data["website"]["video_maxsize"];
		
		$form["audio_folder"] 	= $this->data["website"]["audio_folder"];
		$form["audio_type"] 	= $this->data["website"]["audio_type"];
		$form["audio_maxsize"] 	= $this->data["website"]["audio_maxsize"];
		
		$form["file_folder"] 	= $this->data["website"]["file_folder"];
		$form["file_type"] 		= $this->data["website"]["file_type"];
		$form["file_maxsize"] 	= $this->data["website"]["file_maxsize"];
		
		
		$this->data["form"] = $form;
		
		$this->data["message"] = $message;
		
		$this->render("form_edit_media", $this->data);
	}
	
	function actionSave_media()
	{
		$website = website::model()->findByPk(1);
		
		//$website->image_folder 	= Yii::app()->getRequest()->getPost("image_folder");
		$website->image_type		= Yii::app()->getRequest()->getPost("image_type");
		$website->image_maxsize		= Yii::app()->getRequest()->getPost("image_maxsize");
		
		//$website->file_folder 	= Yii::app()->getRequest()->getPost("file_folder");
		$website->file_type			= Yii::app()->getRequest()->getPost("file_type");
		$website->file_maxsize		= Yii::app()->getRequest()->getPost("file_maxsize");
		

		$website->save();
		
		$this->redirect(array($this->data['controller_id'].'/edit_media',
			"message"=>"Đã lưu thông tin."));
	}
	
	function actionEdit_googleanalytics($message = "")
	{
		$form = array();
		$form["google_analytics"] 	= $this->data["website"]["google_analytics"];
		$this->data["form"] = $form;
		
		$this->data["message"] = $message;
		
		$this->render("form_edit_googleanalytics", $this->data);
	}
	
	function actionSave_googleanalytics()
	{
		$website = website::model()->findByPk(1);
		$website->google_analytics	= Yii::app()->getRequest()->getPost("google_analytics");
		$website->save();
		
		$this->redirect(array($this->data['controller_id'].'/edit_googleanalytics',
			"message"=>"Đã lưu thông tin."));
	}
	
	function actionEdit_mail($message = "")
	{
		$form = array();
		$form["mailer"] 		= $this->data["website"]["mailer"];
		$form["email_from"] 	= $this->data["website"]["email_from"];
		$form["from_name"] 		= $this->data["website"]["from_name"];
		$form["smtp_host"] 		= $this->data["website"]["smtp_host"];
		$form["smtp_username"] 	= $this->data["website"]["smtp_username"];
		$form["smtp_password"] 	= $this->data["website"]["smtp_password"];
		$form["smtp_port"] 		= $this->data["website"]["smtp_port"];
		$this->data["form"] = $form;
		
		$this->data["message"] = $message;
		
		$this->render("form_edit_mail", $this->data);
	}
	
	function actionSave_mail()
	{
		$website = website::model()->findByPk(1);
		
		$website->mailer		= Yii::app()->getRequest()->getPost("mailer");
		$website->email_from	= Yii::app()->getRequest()->getPost("email_from");
		$website->from_name		= Yii::app()->getRequest()->getPost("from_name");
		$website->smtp_host		= Yii::app()->getRequest()->getPost("smtp_host");
		$website->smtp_username	= Yii::app()->getRequest()->getPost("smtp_username");
		$website->smtp_password	= Yii::app()->getRequest()->getPost("smtp_password");
		$website->smtp_port		= Yii::app()->getRequest()->getPost("smtp_port");
		
		$website->save();
		
		$this->redirect(array($this->data['controller_id'].'/edit_mail',
			"message"=>"Đã lưu thông tin."));
	}
	
	function actionEdit_website($message = "")
	{
		$form = array();
		$form["betitle"] 	= $this->data["website"]["betitle"];
		$form["beperpage"] 	= $this->data["website"]["beperpage"];
		$form["fetitle"] 	= $this->data["website"]["fetitle"];
		$form["fefooter"] 	= $this->data["website"]["fefooter"];
		$form["feperpage"] 	= $this->data["website"]["feperpage"];
		$form["enable"] 	= $this->data["website"]["enable"];
		$form["message"] 	= $this->data["website"]["message"];
		
		$this->data["form"] = $form;
		
		$this->data["message"] = $message;
		
		$this->render("form_edit_website", $this->data);
	}
	
	function actionSave_website()
	{
		$website = website::model()->findByPk(1);
		
		$website->betitle		= Yii::app()->getRequest()->getPost("betitle");
		$website->beperpage		= Yii::app()->getRequest()->getPost("beperpage");
		$website->fetitle		= Yii::app()->getRequest()->getPost("fetitle");
		$website->fefooter		= Yii::app()->getRequest()->getPost("fefooter");
		$website->feperpage		= Yii::app()->getRequest()->getPost("feperpage");
		$website->enable		= Yii::app()->getRequest()->getPost("enable");
		$website->message		= Yii::app()->getRequest()->getPost("message");
		
		$website->save();
		
		$this->redirect(array($this->data['controller_id'].'/edit_website',
			"message"=>"Đã lưu thông tin."));
	}
	
	function actionEnable()
	{
		$website = website::model()->findByPk(1);
		$website->enable = 1 - $website->enable;
		$website->save();
		$this->redirect(array($this->data['controller_id'].'/edit_website'));
	}
	
	
	function actionEdit_session($message = "")
	{
		$form = array();
		$form["session_time"] 	= $this->data["website"]["session_time"];
		$this->data["form"] = $form;
		
		$this->data["message"] = $message;
		
		$this->render("form_edit_session", $this->data);
	}
	
	function actionSave_session()
	{
		$website = website::model()->findByPk(1);
		$website->session_time	= Yii::app()->getRequest()->getPost("session_time");
		
		$website->save();
		
		$this->redirect(array($this->data['controller_id'].'/edit_session',
			"message"=>"Đã lưu thông tin."));
	}
	

	
	function actionPhpinfo()
	{
		phpinfo();
		
		//so dien thoai anh loi: 0938 932 946
		
	}
	
}